<template>
	<view>
		<!-- <view class="search">
			<u--input v-model="search.sfz" border="surround" placeholder="请输入身份证号" />
			<u--input v-model="search.xh" border="surround" placeholder="请输入学号" />
			<u-button type="primary" text="搜索" @click="searchInfo"></u-button>
		</view> -->
		<view class="title">
			{{!!search.xh?'学员信息':'暂无学员信息'}}
		</view>
		<view class="body" v-if="!!info">
			<u-cell-group>
				<u-cell title="学号" :value="search.xh"></u-cell>
				<u-cell title="姓名" :value="info.tname"></u-cell>
				<u-cell title="性别" :value="info.sex"></u-cell>
				<!-- <u-cell title="年龄" :value=""></u-cell> -->
				<u-cell title="政治面貌" :value="dy(info.pa)"></u-cell>
				<u-cell title="本人电话" :value="info.phone"></u-cell>
				<u-cell title="单位" :value="info.cp"></u-cell>
				<u-cell title="第一专业" v-if="info.oneEnter">
					<view slot="value">
						<view>
							{{info.oneEnter&&info.oneEnter.termTitle}}
						</view>
					</view>
				</u-cell>
				<u-cell title="第二专业" v-if="info.twoEnter">
					<view slot="value">
						<view>
							{{info.twoEnter&&info.twoEnter.termTitle}}
						</view>
					</view>
				</u-cell>
				<u-cell title="第三专业" v-if="info.threeEnter">
					<view slot="value">
						<view>
							{{info.threeEnter&&info.threeEnter.termTitle}}
						</view>
					</view>
				</u-cell>
				<u-cell title="第四专业" v-if="info.fourEnter">
					<view slot="value">
						<view>
							{{info.fourEnter&&info.fourEnter.termTitle}}
						</view>
					</view>
				</u-cell>
				<u-cell title="第五专业" v-if="info.fiveEnter">
					<view slot="value">
						<view>
							{{info.fiveEnter&&info.fiveEnter.termTitle}}
						</view>
					</view>
				</u-cell>
			</u-cell-group>
			<view class="money" v-if="!jiaofei">
				<view class="tel">
					<view>
						优惠后共需缴费<span style="color: red;">{{info.amount}}</span>元
					</view>
				</view>
				<view class="btn">
					<u-button type="warning" @click="submit">确认缴费</u-button>
				</view>
			</view>
			<view class="success" v-else>
				当前学员已缴费成功
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				search: {
					token:'',
					xh:''
				},
				info: null,
				show: false,
				jiaofei:false,
			}
		},
		onLoad(e) {
			console.log(e);
			this.search.token = uni.getStorageSync('token')
			if (e.xh) {
				this.search.xh = e.xh
				this.searchInfo()
			}
		},
		computed: {
			dy() {
				return (val) => {
					return val === '否' ? '群众' : '党员'
				}
			}
		},
		methods: {
			submit() {
				const {oneEnter,twoEnter,threeEnter,fourEnter,fiveEnter} = this.info
				if(!(!!oneEnter || !!twoEnter || !!threeEnter || !!fourEnter || !!fiveEnter))
					return uni.$u.toast('需要先选择课程！才能进行缴费');
				this.$post(this.$api.sureJF,this.search, res => {
					if (res.code === 200) {
						uni.$u.toast('操作成功！请退出当前页面重新进行扫码');
						this.searchInfo()
						// setTimeout(()=>{
							// uni.redirectTo({
							// 	url:'/pages/login/index'
							// })
						// },500)
					} else {
						uni.$u.toast(res.msg ? res.msg : '操作失败！');
					}
				})
			},
			searchInfo() {
				this.$post(this.$api.getInfo, this.search, res => {
					if (res.code === 200) {
						console.log(res);
						this.info = res.data
						this.jiaofei = res.data.jf === '是'
					} else {
						uni.$u.toast(res.msg ? res.msg : '操作失败！');
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.title {
		font-size: 34rpx;
		font-weight: 500;
		margin: 20rpx;
	}

	.money {
		width: 100%;

		.tel {
			width: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
			height: 100rpx;
		}
	}
	.success{
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		font-size: 36rpx;
		font-weight: 600;
		margin: 30rpx;
	}
</style>
